package com.easyboot.web.system.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.easyboot.framework.domain.DataTableDto;
import com.easyboot.web.system.domain.ExamRecord;
import com.easyboot.web.system.mapper.ExamRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @author yushuo
 * @className
 * @descripton TODO
 * @date 2021/3/1 12:27
 **/
@Service
public class ExamRecordService {


    @Autowired
    private ExamRecordMapper examRecordMapper;

    /**
     *
     * @author yushuo
     * @description //角色列表
     * @date 16:38 2021/2/1
     * @param [dto, roleName, roleCode]
     * @return com.easycms.framework.domain.DataTableDto
     **/
    public DataTableDto getList(DataTableDto dto, String courseName, String courseCode){
        LambdaQueryWrapper<ExamRecord> query=new LambdaQueryWrapper<>();
        if(!StrUtil.isEmpty(courseName)){
            query.like(ExamRecord::getCourseName,courseName.trim());
        }
        if(!StrUtil.isEmpty(courseCode)){
            query.like(ExamRecord::getCourseCode,courseCode.trim());
        }
        query.orderByDesc(ExamRecord::getCourseFlag)
                .orderByDesc(ExamRecord::getExamTime) ;
        Page<ExamRecord> page = new Page<>(dto.getPageNumber(), dto.getPageSize());
        IPage<ExamRecord> userIPage = examRecordMapper.selectPage(page, query);
        dto.setTotal(userIPage.getTotal());
        dto.setRows(userIPage.getRecords());
        return dto;
    }


    /**
     *
     * @author yushuo
     * @description 获取职位信息
     * @date 14:43 2021/2/25
     * @param [id]
     * @return com.easycms.web.system.domain.SysPostion
     **/
    public ExamRecord getModel(int id){
        return examRecordMapper.selectById(id);
    }

    public void saveModel(ExamRecord dto){
        if(dto.getId()==0){
            examRecordMapper.insert(dto);
            return;
        }

        examRecordMapper.updateById(dto);
    }
}
